<template>
  <el-dialog :title="title"
             :visible.sync="visible"
             v-loading="loading"
             :before-close="modalClose"
             :close-on-click-modal="false"
             :close-on-press-escape="false"
             width="50%"
             append-to-body>
    <el-form ref="formRef"
             :model="formModel"
             :rules="formRules"
             label-width="120px">
      <el-form-item label="权益名称："
                    prop="name">
        <el-input v-model="formModel.name"
                  clearable
                  class="w-200"
                  placeholder="请输入权益名称"></el-input>
      </el-form-item>
      <el-form-item label="权益内容："
                    prop="content">
        <el-input v-model="formModel.content"
                  type="textarea"
                  :autosize="{ minRows: 2, maxRows: 4}"
                  placeholder="请输入权益内容"></el-input>
      </el-form-item>
      <el-form-item label="前端排序："
                    prop="sortNum">
        <el-input-number v-model="formModel.sortNum"
                         placeholder="请输入排序"
                         class="w-200"
                         clearable></el-input-number>
      </el-form-item>
    </el-form>
    <p align="center">
      <el-button type="info"
                 @click="modalClose">取 消</el-button>
      <el-button type="primary"
                 @click="submitForm">确 定</el-button>
    </p>
  </el-dialog>
</template>
<script>
  export default {
    name: 'setEquityDialog', // C端用户签到权益
    props: {
      equityObj: {
        type: Object,
        default: {}
      },
      visible: {
        type: Boolean,
        default: false
      },
      isShowEquityDetail: {
        type: Boolean,
        default: false
      },
      inviolableTableData: {
        type: Array,
        default: () => ([])
      }
    },
    data () {
      return {
        title: '新增权益',
        loading: false,
        formModel: {
          name: '',
          content: '',
          sortNum: 0,
        },
        formRules: {
          name: [{ required: true, message: '请输入权益名称', trigger: 'blur' }],
          content: [{ required: true, message: '请输入权益内容', trigger: 'blur' }],
          sortNum: [{ required: true, message: '请输入排序', trigger: 'blur' }],
        }
      }
    },
    methods: {
      modalClose () {
        this.$emit('update:visible', false); // 直接修改父组件的属性
      },
      submitForm () {
        this.$refs.formRef.validate((valid) => {
          if (valid) {
            console.log("更新权益",this.formModel)
            this.$emit('childEquityData', this.formModel);
            this.modalClose();
          }
        })
      },
    },
    created () {
      if (this.isShowEquityDetail) {
        this.formModel = this.equityObj;
        this.title = '编辑权益';
      }
    }
  }
</script>
<style scoped lang="scss">
</style>
